<?php
namespace app\admin\services;

use app\common\services\BaseService;

class FrontMenuService extends BaseService
{
    public function getMenusByParentId($pid)
    {
        $service = new MenuService();
        return $service->getMenusByParentId($pid, 'front_menu');
    }

    public function pagination($page, $rows, $sort, $order, $filterRules)
    {
        $viewInstance = $this->_getViewInstance();
        $pid = I('pid', 0, 'intval');
        $filterRules = $this->parseFilterRules($filterRules);
        $str = "(parent_id=$pid or id=$pid)";
        return [
            $viewInstance->where($filterRules)->where($str)->count(),
            $viewInstance->where($filterRules)->where($str)->limit(($page - 1) * $rows, $rows)->select()
        ];
    }
}